var updatePwdCtrl  = new XFApp.client();

XFApp.client.prototype.updatePwd = {
		successCode : 10000,
		urlItems : {			
			updatePasswdURL: basePath+"/register/updatePwdById",
			passwordCheckURL: basePath+"/register/passwordCheck",
		},
		
		formValidate : function(){			
			$("#updateForm").validate({				
		        rules: {
		        	//oldPassword:"required",
		        	password:  {
		        		        required:true,
		        		        minlength:6
		        				},
		        	password2: {
		        		        required:true,
		        		        equalTo: "#password"
		        	           },
				  },
				 messages: {	
					 //oldPassword:"请填写旧密码",
			         password: {
			        	        required:"请填写新密码",
			        	        minlength:$.validator.format("新密码长度必须大于{0}个字符"),
			         		   },
			         password2:{
			        	 		required:"请再次输入密码",
			        	 		equalTo:"两次输入的密码不一致"
			         			},
				  }
		    });
			$("#updateForm").validate();
		},
		
		event : function (){			
			_this = this;
			
			$("#submitBtn").on("click",function(){
				
				if(!$("#oldPassword").val()){
					$("#oldPassword-error").html('请填写旧密码');
				}
				
				if($("#updateForm").validate().form()){
					if(!$("#oldPassword-error").text()){	
						updatePwdCtrl.updatePwd.submit();		
					}
				}				
			});
			//表单验证
			_this.formValidate();
			
			$("#oldPassword").on("blur",function(){
				_this.passwordCheck();
			});			
		},	
		
		passwordCheck:function(){
			var params = {
					id : $("#hiddenId").val(),
					password : $("#oldPassword").val()
			}
			$.ajax({
	    		url :_this.urlItems.passwordCheckURL,
	    		data : params,
	    		dataType : "json",
	    		type : 'post',
	    		async:false,
	    		success : function(data) {				
	    			if(data.code !=_this.successCode){ 
	    				$("#oldPassword-error").html(data.msg);
	    			}else{
	    				$("#oldPassword-error").html("");
	    			}
	    		}
	    	});
		},
		
		submit : function (){
			
			   var entity = {
			        id : $("#hiddenId").val(),					
					password : $("#password").val(),
				}
		    	
		    	$.ajax({
		    		url :_this.urlItems.updatePasswdURL,
		    		data : entity,
		    		dataType : "json",
		    		type : 'post',
		    		success : function(data) {				
		    			if(data.code==_this.successCode){ 
		    				window.webDialogUtil.alert("提示",data.msg);	
		    				$('#updateForm')[0].reset();
		    			}else{
		    				window.webDialogUtil.alert("提示",data.msg);
		    			}
		    		}
		    	});	
			
		},
},

$(function(){	
	updatePwdCtrl.updatePwd.event();
});